package com.woyou.ui.activity.orderdetail;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.citaq.ideliver.R;
import com.woyou.bean.OrderDetail;
import com.woyou.utils.InstallUtils;

/**
 * 订单已送出、订单已确认
 * 
 * @author zhou
 *
 */
public class SendOutOrderViewCreater extends StateViewCreater implements OnClickListener{

	
	public SendOutOrderViewCreater(Context context, ViewControl uiControl,
			OrderDetail detail) {
		super(context, uiControl, detail);
		// TODO Auto-generated constructor stub
		
	}

	@Override
	protected void createView() {
		mViewArr = new View[2];
		View view1 = View.inflate(mContext, R.layout.orderdetial_item_onebutton, null);
		View view2 = View.inflate(mContext, R.layout.orderdetial_item_towbutton, null);
		
		view1.findViewById(R.id.button1).setOnClickListener(this);
		view2.findViewById(R.id.button2).setOnClickListener(this);
		TextView cancelBtn = (TextView) view2.findViewById(R.id.button3);
		cancelBtn.setOnClickListener(this);
		if(mDetail.getCancelType()==1){
			cancelBtn.setVisibility(View.INVISIBLE);
		} else {
			cancelBtn.setVisibility(View.VISIBLE);
		}
		
		mViewArr[0] = view1;
		mViewArr[1] = view2;
		
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.button1:
			if (mDetail != null) {
				callPhone(mDetail.getsPhone());
			}
			break;
			
		case R.id.button2:
			mUiControl.popConfirmDialog();
			break;
			
		case R.id.button3:
			mUiControl.popCancelDialog();
			break;

		default:
			break;
		}
	}
	
	/**
	 * 拨打电话
	 */
	private void callPhone(String str) {
		// 用intent启动拨打电话
		Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + str));
		if(InstallUtils.isIntentAvailable(mContext, intent)){
			mContext.startActivity(intent);
		}
	}
	

}
